
let {src,dest,watch} = require('gulp'),
    sass = require('gulp-sass')(require('sass')),
    cssnano = require('gulp-cssnano'),
    rename = require('gulp-rename'),
    uglify = require('gulp-uglify'),
    babel = require('gulp-babel'),
    htmlmin = require('gulp-htmlmin'),
    imagemin = require('gulp-imagemin');

function fnCopyIndex(){
    return src('./src/index.html')
    .pipe(dest('./dist'));
}

function fnLib(){
    return src('./src/lib/font/*')
    .pipe(dest('./dist/font'));
}
function fnData(){
    return src('./src/data/*')
    .pipe(dest('./dist/data'));
}
function fnCSS(){
    return src('./src/sass/*.scss')
    .pipe(sass())
    // .pipe(cssnano())
    .pipe(rename({suffix : '.min'}))
    .pipe(dest('./dist/css'));
}

function fnJS(){
    return src('./src/js/*.js')
    .pipe(babel({
        "presets" : ['@babel/env']
    }))
    .pipe(uglify())
    .pipe(rename({suffix : '.min'}))
    .pipe(dest('./dist/js'));
}

function fnHTML(){
    return src('./src/html/*.html')
    .pipe(htmlmin())
    .pipe(dest('./dist/html'));
}

function fnImg(){
    return src('./src/img/*/*')
    .pipe(imagemin())
    .pipe(dest('./dist/img'));
}
// function fnFont(){
//     return src('./src/font/*')
//     .pipe(rename())
//     .pipe(dest('./dest/font'))
// }
function fnWatch(){
    watch('./src/index.html',fnCopyIndex);
    watch('./src/sass/*.scss',fnCSS);
    watch('./src/js/*.js',fnJS);
    watch('./src/html/*.html',fnHTML);
    watch('./src/img/*',fnImg);
}

exports.copyIndex = fnCopyIndex;
exports.css = fnCSS;
exports.js = fnJS;
exports.html = fnHTML;
exports.img = fnImg;
exports.default = fnWatch;
exports.lib = fnLib;
exports.data = fnData;